package com.njbtd.common;

import lombok.Data;

/**
 * @ClassName R
 * @Description TODO
 * @Author leolinzc
 * @Date 24.5.6 14:59
 * @Version 1.0
 */
@Data
public class R<T> {

    /**
     * 成功状态码
     */
    private static final String CODE_SUCCESS = "0";
    /**
     * 通用失败状态码
     */
    private static final String CODE_FAILURE = "-1";

    /**
     * 成功信息
     */
    private static final String MESSAGE_SUCCESS = "success";
    /**
     * 通用失败信息
     */
    private static final String MESSAGE_FAILURE = "failure";

    private String code;
    /**
     * 状态码中文信息，主要用于友好提示UI端用户
     */
    private String message;
    /**
     * 结果集对象
     */
    private T data;

    private R() {

    }
    private R(String code, String message, T data) {
        this.code = code ;
        this.message = message ;
        this.data = data ;
    }

    public static final R success() {
        return new R(CODE_SUCCESS, MESSAGE_SUCCESS, null) ;
    }
    public static final R success(String message) {
        return new R(CODE_SUCCESS, message, null) ;
    }
    public static final <T> R success(T data) {
        return new R(CODE_SUCCESS, MESSAGE_SUCCESS, data) ;
    }
    public static final <T> R success(String message, T data) {
        return new R(CODE_SUCCESS, message, data) ;
    }


    public static final R failure() {
        return new R(CODE_FAILURE, MESSAGE_FAILURE, null) ;
    }
    public static final R failure(String message) {
        return new R(CODE_FAILURE, message, null) ;
    }
    public static final <T> R failure(T data) {
        return new R(CODE_FAILURE, MESSAGE_FAILURE, data) ;
    }
    public static final <T> R failure(String message, T data) {
        return new R(CODE_FAILURE, message, data) ;
    }
}
